package com.gxa.web_admin.controller.accesscontroller;

import com.gxa.common.R;
import com.gxa.modules.pojo.*;
import com.gxa.modules.service.accessservice.RoleService;
import com.gxa.modules.service.accessservice.impl.RoleServiceImpl;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Date;
import java.util.ArrayList;

/**
 * 角色管理
 */
@RestController
@RequestMapping(value = "role")
@Api(value = "角色管理模块",tags = "角色管理API")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 查询所有角色信息
     * @return 返回所有角色信息
     */
    @RequestMapping(value = "selectRole",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有角色信息接口",notes = "根据传入信息查询角色信息",httpMethod = "GET", response = String.class)
    @ApiImplicitParams({
        @ApiImplicitParam(name = "roleName",value = "角色名称",paramType = "query",dataType = "String"),
        @ApiImplicitParam(name = "page",value = "当前页码",paramType = "query",dataType = "String",required = true),
        @ApiImplicitParam(name = "size",value = "每页显示条数",paramType = "query",dataType = "String",required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R selectRole(String roleName,String page,String size){
        return roleService.selectRole(roleName,page,size);
    }


    /**
     * 新增角色
     * @return 返回成功
     */
    @RequestMapping(value = "insertRole",method = RequestMethod.POST)
    @ApiOperation(value = "新增角色接口",notes = "新增角色",httpMethod = "POST", response = String.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R insertRole(@RequestBody @ApiParam(name = "insertRoleJson",
            value = "角色名称、角色类型id、启用状态、创建时间",required = true) Role role,String resourceId){
        return roleService.insertRole(role,resourceId);
    }


    /**
     * 删除角色
     * @return 返回删除成功
     */
    @RequestMapping(value = "deleteRole",method = RequestMethod.POST)
    @ApiOperation(value = "删除角色接口",notes = "根据传入id删除角色",httpMethod = "POST", response = String.class)
    @ApiImplicitParam(name = "roleId",value = "角色id",paramType = "query",dataType = "String",required = true)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R deleteRole(String roleId){

        return roleService.deleteRole(roleId);
    }

    /**
     * 修改角色
     * @return 返回成功
     */
    @RequestMapping(value = "updateRole",method = RequestMethod.POST)
    @ApiOperation(value = "修改角色接口",notes = "修改角色",httpMethod = "POST", response = String.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateRole(@RequestBody @ApiParam(name = "updateRoleJson",
            value = "角色id、角色名称、角色类型id、启用状态、修改时间",required = true) Role role,String resourceId){
        return roleService.updateRole(role,resourceId);
    }
}
